package br.com.absolutech.study.chapter7.pag322;

import java.util.Comparator;
import java.util.PriorityQueue;

public class PriorityQueueTest {

	static class PQsort implements Comparator<Integer> {
		public int compare(Integer one, Integer two) {
			return two - one;
		}
	}

	public static void main(String[] args) {

		int[] ia = { 1, 5, 3, 7, 6, 9, 8 };
		PriorityQueue<Integer> pq1 = new PriorityQueue<Integer>();

		for (int x : ia) { //carrega a fila
			pq1.offer(x);
		}
		for (int x : ia) { //revisa a fila
			System.out.print(pq1.poll() + " ");
		}
		System.out.println("");

		PQsort pqs = new PQsort();
		PriorityQueue<Integer> pq2 = new PriorityQueue<Integer>(10, pqs);
		for (int x : ia) { //carrega a fila
			pq2.offer(x);
		}

		System.out.println("size " + pq2.size());
		System.out.println("peek " + pq2.peek());
		System.out.println("size " + pq2.size());
		System.out.println("peek " + pq2.poll());
		System.out.println("size " + pq2.size());

		for (int x : ia) { //revisa a fila
			System.out.print(pq2.poll() + " ");
		}
	}
}
